define(["drawable"], function(Drawable){
       
    Stats.prototype = new Drawable();
    
    function Stats(){
        var score = 0;
        var levelName = "";

        var fps = 0;
        var frameCount = 0;
        var elapsedMillies = 0;
        var lastTime = Date.now();

        this.setLevelName = function(lvlName){
            levelName = lvlName;
            this.isDirty = true;  
        };
        
        this.getLevelName = function() {
            return levelName;
        };
        
        this.setScore= function(s){
            score = s;
            this.isDirty = true;  
        };
        
        this.addScore = function(s){
            score += s;
            this.isDirty = true;
        };
        
        this.getScore = function() { return score; };
        
        this.calcFps = function() {
            frameCount++;
            var now = Date.now(); 
            elapsedMillies += now - lastTime;
            lastTime = now;
            if(elapsedMillies >= 1000){
                elapsedMillies = 0;
                fps = frameCount;
                frameCount = 0; 
                
                this.isDirty = true;
            }
            return fps;
        };
        
        this.reset = function(){
            this.setScore(0);
            this.setLevelName("");
        };
        
        this.x = 0;
        this.y = 0;
        this.h = 32;
        this.w = 640; // canvas width?
        this.isCollidable = false;
        this.lastTime = Date.now();
        this.elapsedMillies = 0;
        this.setScore(0);
    }
    
    
    
    Stats.prototype.draw = function(context){
        
        
        var fps = this.calcFps();        
        
        if(this.isDirty){
            this.isDirty = false;
            
            context.clearRect(this.x, this.y, this.w, this.h*2);
            
            
            var textHeight = 28;
            var posX = this.w - (this.w/6);
            var posY = this.h - (this.h - textHeight);
            
            context.save();
            context.font = textHeight + "px Arial";
            context.fillStyle= "rgb(255,128,0)";        
            
            context.shadowColor = '#000';
            context.shadowBlur = 5;
            context.shadowOffsetX = 2;
            context.shadowOffsetY = 2;
            
            context.fillText(this.getScore(), posX, posY);
            
            posX = 24;
            context.fillText(this.getLevelName(), posX, posY);            
            
            context.font = textHeight/2 + "px Arial";
            context.fillText(fps + " fps", posX, posY + textHeight/2 + 4);

            
            context.restore();
        }
    };
        
    
    return Stats;
});